import {http} from '../../http'

import {
  SimpleUserInfo,
  TokenInfo,
  UserProfileExtVo
} from './response'
import {
  GetUserRecommend, GetUserSimpleInfoParam,
  RefreshTokenParam,
  UserLoginParam,
  UserProfileParam,
  WxLoginParam,
  WxPhoneBindParam
} from './param'

//传统账号密码登录
const login = (params: UserLoginParam) => http.post<UserLoginParam, TokenInfo>('/user/login', params)

//传统账号密码登录
const register = (params: UserLoginParam) => http.post<UserLoginParam, TokenInfo>('/user/register', params)
//判断是否登录
const isLogin = (params: UserLoginParam) => http.post<UserLoginParam, TokenInfo>('/logged', params)

//微信登录
const wxLogin = (params: WxLoginParam) => http.post<WxLoginParam, TokenInfo>('/user/login/wx', params)

//微信注册
const registerByWx = (params: WxLoginParam) => http.post<WxLoginParam, void>('/user/register/wx', params)

//绑定微信信息
const bindWxUserInfo = (params: WxPhoneBindParam) => http.put<WxPhoneBindParam, void>('/user/wx/info', params)

//绑定微信信息
const bindWxPhone = (params: WxPhoneBindParam) => http.put<WxPhoneBindParam, void>('/user/wx/phone', params)

//获取当前用户信息
const getCurrentUserInfo = () => http.get<void, any>('/user/userinfor')

//修改用户信息
const updateUserInfo = (params: UserProfileParam) => http.put<UserProfileParam, void>('/user/profile', params)

//修改用户密码
const updatePwd = (params: UserProfileParam) => http.put<UserProfileParam, void>('/user/updatepwd', params)

//刷新token
const refreshToken = (params: RefreshTokenParam) => http.put<RefreshTokenParam, TokenInfo>('/user/token/refresh', params)

//获取推荐用户
const getUserRecommend = (params: GetUserRecommend) => http.get<GetUserRecommend, SimpleUserInfo[]>(`/school/${params.schoolId}/user/recommend`)

//获取用户简易信息
const getUserSimpleInfo = (params: GetUserSimpleInfoParam) => http.get<GetUserSimpleInfoParam, UserProfileExtVo>('/user/simple/info', params)

export default {
  login,
  register,
  isLogin,
  wxLogin,
  registerByWx,
  bindWxUserInfo,
  bindWxPhone,
  getCurrentUserInfo,
  updateUserInfo,
  refreshToken,
  getUserRecommend,
  getUserSimpleInfo,
  updatePwd
}